// Arrangment and permutation
// 子集（元素无重不可复选）
#include <bits/stdc++.h>
using namespace std;

template <typename T>
void printVector(vector<T> nums, bool withEnter=true)
{
    for (auto n : nums)
    {
        cout << n << ' ';
    }
    if(withEnter)
        cout<<endl;
}


// [排列]
// 题目给你输入一个无重复元素的数组 nums，
// 返回其所有可能的子集。
void backtrack(vector<int> &nums, vector<vector<int>> &res, vector<int> &path, int startIndex){
    res.push_back(path);
    for(int i = startIndex; i < nums.size(); i++){
        path.push_back(nums[i]);
        backtrack(nums, res, path,i+1);
        path.pop_back();
    }
    return;
}

vector<vector<int>> subsets(vector<int> nums){
    vector<vector<int>> res;
    vector<int> path;
    backtrack(nums, res, path,0);
    return res;
}


int main(){
    vector<int> nums = {1,2,3};
    vector<vector<int>> res = subsets(nums);
    for(auto line : res){
        printVector(line);
    }
    return 0;
}
